package com.example.sulingorder.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.example.sulingorder.entity.OrderEarthEntity;
import com.example.sulingorder.service.OrderService;
import com.example.sulingorder.vo.HelpFormDataVo;
import com.example.sulingorder.vo.ReleaseOrderInfoVo;
import com.example.sulingorder.vo.ReleaseOrderVo;
import com.xiao.sulingpublic.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author: 1322127758@qq.com
 * @date: 2022/3/14 16:10
 * @作用: 发布订单相关业务
 */
@RestController
@RequestMapping("/order/myorder")
public class MyOrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 发布订单 处理帮领性业务
     * @param releaseOrderVo :订单相关信息
     * @param releaseOrderInfoVo :领取需要的信息
     * @return :返回订单token, 该token为订单数据在redis中的key
     */
    @PostMapping("/submit/release_order")
    public String releaseOrder(ReleaseOrderVo releaseOrderVo, ReleaseOrderInfoVo releaseOrderInfoVo, OrderEarthEntity orderEarthEntity, String formCode){
        if(null != releaseOrderVo && null != releaseOrderInfoVo && !StringUtils.isEmpty(formCode)){
            try{
                return orderService.saveOrder(releaseOrderVo,releaseOrderInfoVo,orderEarthEntity,formCode);
            }catch(Exception e){}
        }
        return null;
    }

    /**
     * 发布订单 处理帮买业务
     * @param helpFormDataVo :订单所有相关信息
     * @return :返回订单token, 该token为订单数据在redis中的key
     */
    @PostMapping("/submit/help_buy")
    public R helpBuy(@RequestBody @Valid HelpFormDataVo helpFormDataVo){
        if(null != helpFormDataVo){
            try{
                return orderService.saveHelpBuyOrder(helpFormDataVo);
            }catch(Exception e){
                return R.error("支付失败");
            }
        }
        return R.error("支付失败");
    }
}
